package com.heima.xiyuanmall.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.heima.mvplibrary.base.BaseActivity;
import com.heima.mvplibrary.dailog.LoadingDailog;
import com.heima.xiyuanmall.R;
import com.heima.xiyuanmall.presenter.LoginPresenter;

import me.jessyan.autosize.utils.ScreenUtils;

public class LoginActivity extends BaseActivity<LoginPresenter> {


    private EditText etUsername;
    private EditText etPassword;
    private Button btRegister;
    private Button btLogin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();//隐藏标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Translate();
    }

    @Override
    protected void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.bt_login:
                LoadingDailog loadingDailog = new LoadingDailog.Builder(this).create();
                loadingDailog.show();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        start(SudokuGameActivity.class);
                        loadingDailog.dismiss();
                        finish();
                    }
                }, 3000);
                break;
            case R.id.bt_register:
                break;
        }
    }

    /**
     * 动画平移
     *
     */
    public void Translate() {
        TranslateAnimation translateAni = new TranslateAnimation(0,0,
                0, 0,
                0, -500,
                0, 0);//设置平移的起点和终点

        //设置动画执行的时间，单位是毫秒
        translateAni.setDuration(800);
        // 启动动画
        findViewById(R.id.ll_context).startAnimation(translateAni);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initData() {
        ((TextView)findViewById(R.id.title)).setTypeface(Typeface.createFromAsset(getAssets(),"fonts/HYShangWeiShouShuW.ttf"));
        etUsername = (EditText) findViewById(R.id.et_username);
        etPassword = (EditText) findViewById(R.id.et_password);
        btRegister = (Button) findViewById(R.id.bt_register);
        btLogin = (Button) findViewById(R.id.bt_login);

    }

    @Override
    public void initListener() {
        btLogin.setOnClickListener(this);
        btRegister.setOnClickListener(this);
    }
}